<template>
  <div o-Container>
    <div class="row">
      <div class="left">
        <div class="title">主题推荐类型</div>
        <div class="scroll">
          <div
            class="scroll-item"
            :class="typeList.value == item.ID ? 'active' : ''"
            v-for="(item, i) in typeList.options"
            :key="item.ID"
            @click="changeTab(item, i)"
          >
            {{ item.Name }}
          </div>
        </div>
      </div>
      <div class="right">
        <div class="top_box">
          <div class="search_box">
            <img
              src="/static/skin/herodoo/main/platform/home/img/search.png"
              alt=""
            />
            <input
              v-model="searchValue"
              type="text"
              placeholder="请输入搜索内容"
              @keydown.enter="searchEnterKeyPress"
              @blur="searchEnterKeyPress"
            />
          </div>
          <div class="button_box">
            <button @click="addNew()">添加推荐</button>
          </div>
        </div>
        <o-list v-bind:source="list.contract">
          <template slot="config" slot-scope="scope">
            <div class="img_box">
              <img
                @click="look(scope)"
                src="/static/skin/default/MCS/AIGC/Inventory/images/chakan.png"
                alt=""
              />
              <img
                @click="edit(scope)"
                src="/static/skin/default/MCS/AIGC/Inventory/images/bianji.png"
                alt=""
              />
              <img
                @click="del(scope)"
                src="/static/skin/default/MCS/AIGC/Inventory/images/shanchu.png"
                alt=""
              />
            </div>
          </template>
        </o-list>
      </div>
    </div>

    <editRecommend ref="editRecommend" @reload="reload"></editRecommend>
  </div>
</template>

<script>
  import editRecommend from "./Components/editRecommend.vue";

  export default {
    components: {
      editRecommend
    },
    name:
      "mms_platform_company_list" /* 这个name暂时不知道用啥用，根据官方文档说的是方便排错的 */,
    data() {
      return {
        octopus: this.$parent.octopus,
        list: {
          contract: {
            data: {
              id: 1281, // 菜单表的八爪鱼ID
              cellData: [
                {
                  name: "EquityName",
                  width: 300,
                  filterKey: "like",
                  filterValue: ""
                }, // EquityName
                {name: "Sort"}, // 排序优先级
                {
                  name: "SubjectName",
                  width: 150
                }, // 主题名
                {name: "CreateUserID"}, // 创建人
                {name: "CreateTime", width: 150}, // 创建时间
                {name: "EquityID", show: false}, // 权益ID
                {name: "PosterPath", show: false}, // PosterPath
                {
                  name: "SubjectID",
                  show: false,
                  filterKey: "=",
                  filterValue: ""
                }, // 主题\推荐ID
                {name: "ID", show: false}, // ID
                {name: "UpdateTime", show: false}, // 修改时间
                {name: "UpdateUserID", show: false}, // 修改人
                {
                  name: 'TypeID', show: false, filterKey: "=",
                  filterValue: 1
                }
              ],
              paramData: {}
            },
            configWidth: 90,
            showNumber: true
          }
        },
        isEdit: false,
        typeList: {
          value: "", //选中的主题类型ID
          options: []
        },
        searchValue: ""
      };
    },
    created() {
      this.init();
    },
    methods: {
      async init() {
        await this.api_1276();
        const data = this.list.contract.data;
        const company = this.octopus.passport.authorization.company;
        data.paramData.CompanyID = company == 1 ? "NULL" : company;
      },
      addNew() {
        let find = this.typeList.options.find(x => x.ID == this.typeList.value);
        this.$refs.editRecommend.drawerOpen(null, "CREATE", find);
      },
      look(row) {
        let find = this.typeList.options.find(x => x.ID == this.typeList.value);
        this.$refs.editRecommend.drawerOpen(row.data.row, "look", find);
      },
      edit(row) {
        let find = this.typeList.options.find(x => x.ID == this.typeList.value);
        this.$refs.editRecommend.drawerOpen(row.data.row, "UPDATE", find);
      },
      del(row) {
        this.$confirm(`确定删除这个主题推荐吗?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          // type: 'warning'
          center: true
        })
          .then(res => {
            this.del_1281(row.data.row.ID);
          })
          .catch(() => {
            console.log("取消了");
          });
      },
      del_1278(ID) {
        this.octopus.request.api.post(
          "/Octopus/Engine/Item",
          {
            id: 1278, // 菜单表的八爪鱼ID
            type: "DELETE",
            value: ID,
            cellData: [
              {name: "Name"}, // 主题/热点名称
              {name: "Sort"}, // 排序优先级
              {name: "CreateUserID"}, // 创建人
              {name: "CreateTime"}, // 创建时间
              {name: "ID"}, // ID
              {name: "Status"}, // 状态
              {name: "TypeID"}, // 类型ID
              {name: "UpdateTime"}, // 维护时间
              {name: "UpdateUserID"} // 维护人
            ]
          },
          // 处理回调事件，通过分析data.status.code的状态来实现。
          data => {
            if (data.status.code === 200) {
              this.list.contract.control.load();
            } else {
              this.octopus.tips.error(data);
            }
          }
        );
      },
      api_1276() {
        this.octopus.request.api.post(
          "/Octopus/Engine/List",
          {
            id: 1276, // 菜单表的八爪鱼ID
            cellData: [
              {name: "Name"}, // 主题/热点名称
              {name: "Sort"}, // 排序优先级
              {name: "CreateUserID"}, // 创建人
              {name: "CreateTime"}, // 创建时间
              {name: "ID"}, // ID
              {name: "Status"}, // 状态
              {name: "TypeID", filterKey: "=", filterValue: 1}, // 类型ID
              {name: "UpdateTime"}, // 维护时间
              {name: "UpdateUserID"} // 维护人
            ]
          },
          // 处理回调事件，通过分析data.status.code的状态来实现。
          data => {
            if (data.status.code === 200) {
              this.typeList.options = data.content.queryData;
              // 如果大于 0
              if (this.typeList.options.length > 0) {
                this.typeList.value = data.content.queryData[0].ID;
                this.list.contract.data.cellData[7].filterValue = this.typeList.value;
              }
              else{
                // TODO 处理没有数据的情况
              }
              this.list.contract.control.load();
            } else {
              this.octopus.tips.error(data);
            }
          }
        );
      },
      changeTab(item, i) {
        this.typeList.value = item.ID;
        this.list.contract.data.cellData[7].filterValue = this.typeList.value;
        this.list.contract.control.load();
      },
      searchEnterKeyPress() {
        this.list.contract.data.cellData[0].filterValue = this.searchValue;
        this.list.contract.control.load();
      },
      reload() {
        this.list.contract.control.load();
      }
    },
    props: ["oData"]
  };
</script>
<style scoped>
  .top_box {
    width: 100%;
    height: 5.3rem;
    display: flex;
    justify-content: space-between;
    margin-top: 2rem;
    padding-bottom: 1.2rem;
    box-sizing: border-box;
  }
  .top_box .search_box {
    width: 32rem;
    height: 100%;
    border: 1px solid #f0f0f0;
    border-radius: 4rem;
    display: flex;
    justify-content: space-between;
    padding: 0 0.8rem;
    box-sizing: border-box;
  }
  .top_box .search_box input {
    border: none;
    outline: none;
    width: 70%;
  }
  .top_box .search_box img {
    cursor: pointer;
  }
  .top_box .button_box button {
    width: 15rem;
    height: 100%;
    border-radius: 4rem;
    border: none;
    color: #fff;
    background-color: #f78c52;
    box-shadow: 0px -3px 4px 0px rgba(204, 190, 186, 0.4);
    font-size: 1.7rem;
    cursor: pointer;
  }
  .top_box .button_box button {
    margin-right: 1.3rem;
  }
  .el-message-box {
    background-color: #fff !important;
  }
  .img_box {
    display: flex;
    justify-content: space-between;
    width: 100%;
  }
  .img_box img {
    width: 25px;
    cursor: pointer;
  }
  .disable {
    cursor: not-allowed;
    opacity: 0.5;
  }
  >>> .Content {
    height: 84vh !important;
    width: 100% !important;
  }
  .row {
    display: flex;
    flex-direction: row;
  }
  .row .left {
    width: 15vw;
    padding: 2vh;
    overflow: hidden;
  }
  .left .title {
    font-size: 2rem;
    padding-bottom: 20px;
  }
  .left .scroll {
    width: 100%;
    height: calc(100% - 1vh);
    overflow-y: auto;
    overflow-x: hidden;
  }
  .left .scroll-item {
    font-size: 1rem;
    border: 1px solid #f0f0f0;
    padding: 10px;
    text-align: center;
    cursor: pointer;
  }
  .left .active {
    border-color: #f78c52;
  }
  .row .right {
    width: calc(100% - 16vw);
  }
</style>
